package com.superman.supermarket.client.composite.refundlist;

import java.util.List;
import java.util.Map;

import com.google.gwt.core.client.GWT;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Widget;
import com.superman.mvpframe.client.utils.XJsonUtil;
import com.superman.supermarket.client.composite.IUIModule;
import com.superman.supermarket.client.composite.orderlist.opt.OrderListOpButton;
import com.superman.supermarket.client.constant.RefundStatusConstants;

/**
 * 退款模块
 * 
 * @author superman
 * @version 2018年8月21日下午10:14:00
 */
public class RefundModule extends Composite implements IUIModule {

	interface RefundModuleUiBinder extends UiBinder<Widget, RefundModule> {
	}

	private static RefundModuleUiBinder uiBinder = GWT.create(RefundModuleUiBinder.class);

	@UiField
	FlowPanel optpanel;
	@UiField
	RefundSkuModule refundskumodule;
	@UiField
	Image storelogo;
	@UiField
	HTML storenamehtml, statushtml;

	/**
	 * 构造方法
	 * 
	 * @author superman
	 * @version 2018年8月21日 下午10:14:02
	 */
	public RefundModule() {
		initWidget(uiBinder.createAndBindUi(this));
	}

	@Override
	public Map<String, Object> getData() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void setData(Map<String, Object> map) {
		storelogo.setUrl(String.valueOf(map.get("STORE_LOGO")));
		storenamehtml.setText(String.valueOf(map.get("STORE_NAME")));

		int refundStatus = (int) Double.parseDouble(String.valueOf(map.get("REFUND_STATE")));
		statushtml.setText(RefundStatusConstants.getDescByStatus(refundStatus));

		refundskumodule.setData(map);

		if (map.get("OP") != null && XJsonUtil.getOnlyList((JSONArray) map.get("OP")).size() > 0) {
			optpanel.setVisible(true);
			optpanel.clear();
			List<Object> ops = XJsonUtil.getOnlyList((JSONArray) map.get("OP"));
			for (Object object : ops) {
				int op = (int) Double.parseDouble(String.valueOf(object));
				OrderListOpButton orderListOpButton = new OrderListOpButton(map, op);
				optpanel.add(orderListOpButton);
			}
		}
	}

}
